package com.lin.blog.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.lin.blog.valid.UserUpdateGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Range;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>
 * 
 * </p>
 *
 * @author lin
 * @since 2020-03-08
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="User对象", description="")
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户ID")
    private Long id;

    @NotEmpty(message = "用户名不能为空",groups = {UserUpdateGroup.class})
    @ApiModelProperty(value = "用户名")
    private String username;

    @NotEmpty(message = "密码不能为空")
    @ApiModelProperty(value = "密码")
    private String password;

    @NotEmpty(message = "用户昵称",groups = {UserUpdateGroup.class})
    @ApiModelProperty(value = "用户昵称")
    private String nickname;

    @ApiModelProperty(value = "用户头像")
    private String headImage;

    @NotEmpty(message = "手机号码不能为空",groups = {UserUpdateGroup.class})
    @Pattern(message = "手机号码格式不正确",regexp = "^(?:\\+?86)?1(?:3\\d{3}|5[^4\\D]\\d{2}|8\\d{3}|7(?:[01356789]\\d{2}|4(?:0\\d|1[0-2]|9\\d))|9[189]\\d{2}|6[567]\\d{2}|4(?:[14]0\\d{3}|[68]\\d{4}|[579]\\d{2}))\\d{6}$" ,groups = {UserUpdateGroup.class})
    @ApiModelProperty(value = "手机号")
    private String phone;

    @Range(message = "性别不正确", min = 0,max = 2,groups = {UserUpdateGroup.class})
    @ApiModelProperty(value = "性别 0 - 未设置  1 -  男  2  -  女")
    private Integer sex;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @ApiModelProperty(value = "最后一次登录时间")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private LocalDateTime lastTime;


    @ApiModelProperty(value = "真实姓名")
    private String realName;

    @NotEmpty(message = "QQ号码不能为空",groups = {UserUpdateGroup.class})
    @Pattern(message = "QQ格式不正确",regexp = "^[1-9][0-9]{4,9}",groups = {UserUpdateGroup.class})
    @ApiModelProperty(value = "qq")
    private String qq;

    @NotEmpty(message = "邮箱不能为空",groups = {UserUpdateGroup.class})
    @Email(message = "邮箱格式不正确",regexp = "^[0-9a-z]+\\w*@([0-9a-z]+\\.)+[0-9a-z]+$",groups = {UserUpdateGroup.class})
    @ApiModelProperty(value = "邮箱")
    private String email;

    @ApiModelProperty(value = "简介")
    private String intro;


}
